package cn.iocoder.yudao.module.design.service.flowtaskaction;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.design.controller.admin.flowtaskaction.vo.FlowTaskActionCreateReqVO;
import cn.iocoder.yudao.module.design.controller.admin.flowtaskaction.vo.FlowTaskActionExportReqVO;
import cn.iocoder.yudao.module.design.controller.admin.flowtaskaction.vo.FlowTaskActionPageReqVO;
import cn.iocoder.yudao.module.design.controller.admin.flowtaskaction.vo.FlowTaskActionUpdateReqVO;
import cn.iocoder.yudao.module.design.convert.flowtaskaction.FlowTaskActionConvert;
import cn.iocoder.yudao.module.design.dal.dataobject.flowtaskaction.FlowTaskActionDO;
import cn.iocoder.yudao.module.design.dal.mysql.flowtaskaction.FlowTaskActionMapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;

/**
 * 任务处理模型 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class FlowTaskActionServiceImpl implements FlowTaskActionService {

    @Resource
    private FlowTaskActionMapper flowTaskActionMapper;

    @Override
    public Long createFlowTaskAction(FlowTaskActionCreateReqVO createReqVO) {
        // 插入
        FlowTaskActionDO flowTaskAction = FlowTaskActionConvert.INSTANCE.convert(createReqVO);
        flowTaskActionMapper.insert(flowTaskAction);
        // 返回
        return flowTaskAction.getId();
    }

    @Override
    public void updateFlowTaskAction(FlowTaskActionUpdateReqVO updateReqVO) {
        // 校验存在
        this.validateFlowTaskActionExists(updateReqVO.getId());
        // 更新
        FlowTaskActionDO updateObj = FlowTaskActionConvert.INSTANCE.convert(updateReqVO);
        flowTaskActionMapper.updateById(updateObj);
    }

    @Override
    public void deleteFlowTaskAction(Long id) {
        // 校验存在
        this.validateFlowTaskActionExists(id);
        // 删除
        flowTaskActionMapper.deleteById(id);
    }

    private void validateFlowTaskActionExists(Long id) {
        if (flowTaskActionMapper.selectById(id) == null) {
//            throw exception("");
        }
    }

    @Override
    public FlowTaskActionDO getFlowTaskAction(Long id) {
        return flowTaskActionMapper.selectById(id);
    }

    @Override
    public List<FlowTaskActionDO> getFlowTaskActionList(Collection<Long> ids) {
        return flowTaskActionMapper.selectBatchIds(ids);
    }

    @Override
    public PageResult<FlowTaskActionDO> getFlowTaskActionPage(FlowTaskActionPageReqVO pageReqVO) {
        return flowTaskActionMapper.selectPage(pageReqVO);
    }

    @Override
    public List<FlowTaskActionDO> getFlowTaskActionList(FlowTaskActionExportReqVO exportReqVO) {
        return flowTaskActionMapper.selectList(exportReqVO);
    }

}
